<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="include/head::head('组卷系统后台 | 试卷审核')"></head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

    <!--Main Header -->
    <div th:replace="/include/back_header::header"></div>
    <!-- Left side column. contains the logo and sidebar -->
    <div th:replace="/include/back_sidebar::sidebar"></div>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                基本信息表
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="#">试卷管理</a></li>
                <li class="active"><img src=""></li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <!-- /.box-header -->
                        <div class="box-body">
                            <table id="example" class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th>名称</th>
                                    <th>难度</th>
                                    <th>总分</th>
                                    <th>创建人</th>
                                    <th>创建时间</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr th:each="exam,memberStat:${examList.examShowList}">
                                    <td th:text="${exam.examName}"></td>
                                    <td th:text="${exam.examDifficulty}"></td>
                                    <td th:text="${exam.examScore}"></td>
                                    <td th:text="${exam.newCreator}"></td>
                                    <td th:text="${exam.newCreateTime}"></td>
                                    <td th:text="${exam.newStatus} "></td>
                                    <td class="col-operate">
                                        <button type="button" class="btn btn-modify btn-warning btn-sm"
                                                data-toggle="modal"
                                                data-target="#modal-default" th:onclick="download([[${exam.examContent}]])">下载
                                        </button>
                                        <button type="button" class="btn btn-pass btn-success btn-sm" th:onclick="passExam(this,[[${exam.examId}]],[[${exam.examName}]])">通过</button>
                                        <button type="button" class="btn btn-delete btn-danger btn-sm" th:onclick="deleteExam(this,[[${exam.examId}]],[[${exam.examName}]])">拒绝</button>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <!-- Main Footer -->
    <div th:replace="/include/back_footer::footer"></div>

</div>
<!-- ./wrapper -->

<!-- REQUIRED JS SCRIPTS -->
<div th:replace="include/javascript::javascript"></div>
<!-- page script -->
<script>
    $(function () {
        $("#exam-branch").addClass("active");
        $("#trId").hide();
        $('#example').DataTable({
            'paging': true,
            'lengthChange': true,
            'searching': true,
            'ordering': true,
            'bAutoWidth': false,
            'info': true,
            'autoWidth': false,
            'aLengthMenu':[7,10,20],
            'columnDefs': [
                {
                    "targets": [0],
                    "Sorting": false,
                    "render": function (data, type, row, meta) {
                        // var order1 = meta.settings._iDisplayStart + meta.row + 1;
                        // var order2 = order1 + '、';
                        return type === 'display' && data.length > 20 ?
                            '<span title="' + data + '">' + data.substr(0, 16) + '...</span>' :  data;
                    }
                },

            ]
        });
    });

    function deleteExam(obj,id,name){
        var table = $("#example").DataTable();
        var row = table.row($(obj).parents('tr'));
        layer.confirm('确定删除试卷【'+name+'】吗', {icon: 3, title: '提示'}, function (index) {
            $.ajax({
                type: "POST",
                url: "/exam-delete",
                data: {id: id},
                dataType: "json",
                success: function (msg) {
                    if(msg["ok"]){
                        layer.msg("操作成功", {time: 700}, function () {
                            //  window.location.reload();
                            row.remove().draw();
                        });
                    }else {
                        layer.msg("删除失败");
                    }
                }
            });
            layer.close(index);
        });
    };
    function passExam(obj,id,name) {
        var table = $("#example").DataTable();
        var row = table.row($(obj).parents('tr'));
        layer.confirm('确定将试卷【'+name+'】加入试题库吗', {icon: 3, title: '提示'}, function (index) {
            $.ajax({
                type: "POST",
                url: "/exam-pass",
                data: {id: id},
                dataType: "json",
                success: function (msg) {
                    if(msg["ok"]){
                        layer.msg("操作成功", {time: 700}, function () {
                            //  window.location.reload();
                            row.remove().draw();
                        });
                    }else {
                        layer.msg("删除失败");
                    }
                }
            });
            layer.close(index);
        });
    }

    function download(paperPath){
        window.location.href="/download-paper?path="+paperPath;
    }
    $(".sidebar-menu li").click(function (e) {
        $(".sidebar-menu li").removeClass("active");
        $(this).addClass("active");
    });
</script>
</body>
</html>